/*
 * Copyright (c) 2023, 2023,yzc.cn All rights reserved.
 *
 */
package cn.yzc.service.impl;

import cn.yzc.mapper.TaskMapper;
import cn.yzc.mapper.UserTaskMapper;
import cn.yzc.service.UserTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>Project: SpringPro - UserTaskServiceImpl</p>
 * <p>Powered by yzc On 2023-10-26 16:21:37</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Service
public class UserTaskServiceImpl implements UserTaskService {

    @Autowired
    UserTaskMapper userTaskMapper;
    @Autowired
    TaskMapper taskMapper;


    @Transactional
    @Override
    public int updateStatus(int id, int taskId) {
        userTaskMapper.updateStatus(id);
        Map map = userTaskMapper.queryCount(taskId);
        Long total = (Long) map.get("total");
        Long finish = (Long) map.get("finishCount");
        int status = 0;
        if (total == finish) {
            status = 3;
        } else if (total > finish) {
            status = 2;
        }
        int rs = taskMapper.updateStatusInt(taskId, status);

        return rs;
    }
}
